package com.example.demo.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entity.Role;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 角色信息查询
 * @author
 */
@Repository
@Mapper
public interface RoleDao extends BaseMapper<Role> {

    /**
     * 根据用户ID获取角色列表
     * @param sUserId
     * @return
     */
    @Select(value=" SELECT sr.* FROM role sr " +
            " LEFT JOIN users_role sur ON sr.id = sur.fk_role_id " +
            " LEFT JOIN users su ON sur.fk_user_id = su.id " +
            " WHERE su.id = #{sUserId} ")
     List<Role> findSRoleListBySUserId(int sUserId);

    /**
     * 根据资源路径获取角色列表
     * @param sPermissionUrl
     * @return
     */
    @Select(value=" SELECT sr.* FROM role sr " +
            " LEFT JOIN role_permission srp ON sr.id = srp.fk_role_id " +
            " LEFT JOIN permission sp ON srp.fk_permission_id = sp.id " +
            " WHERE sp.url = #{sPermissionUrl} ")
     List<Role> findSRoleListBySPermissionUrl(String sPermissionUrl);
}
